package com.tengju.bff.interfaces.data.vo;

import lombok.Data;

import java.math.BigDecimal;

/**
 * @author chenhang
 * @Date 2020/12/25
 */
@Data
public class AchievementBonusMidDiffDetailVO {

    private String diffTag;

    private BigDecimal diffAchievement;

    private Integer diffChildrenNum;

    private BigDecimal diffProfit;

    private Integer teamRatioType;

    private AchievementBonusMidDetailVO detailVO;

    private AchievementBonusMidDetailVO compareDetailVO;

    public AchievementBonusMidDiffDetailVO(AchievementBonusMidDetailVO detailVO, AchievementBonusMidDetailVO compareDetailVO) {
        if (detailVO == null) {
            diffTag = "add";
            this.compareDetailVO = compareDetailVO;
            return;
        }
        if (compareDetailVO == null) {
            diffTag = "remove";
            this.detailVO = detailVO;
            return;
        }
        this.diffProfit = detailVO.getProfit().subtract(compareDetailVO.getProfit());
        this.diffAchievement = detailVO.getAchievement().subtract(compareDetailVO.getAchievement());
        this.diffChildrenNum = detailVO.getChildrenNum() - compareDetailVO.getChildrenNum();
        if (diffProfit.compareTo(BigDecimal.ZERO) == 0
                && diffAchievement.compareTo(BigDecimal.ZERO) == 0
                && diffChildrenNum == 0) {
            diffTag = "same";
        } else {
            diffTag = "diff";
        }
        this.detailVO = detailVO;
        this.compareDetailVO = compareDetailVO;
        this.teamRatioType = detailVO.getTeamRatioType();
    }

    public String print(StringBuilder exSb) {
        StringBuilder sb = new StringBuilder();
        String diff = String.format("diffTag= %-5s" +
                        ", teamRatioType= %-8s" +
                        ", diffAchievement= %-8s" +
                        ", diffProfit= %-8s" +
                        ", diffChildrenNum= %-5s \r\n",
                diffTag,
                teamRatioType,
                diffAchievement,
                diffProfit,
                diffChildrenNum
        );
        sb.append(exSb).append("\t").append(diff);
        if (detailVO != null) {
            sb.append(exSb).append("\t").append("main:").append(detailVO.toString());
        }
        if (compareDetailVO != null) {
            sb.append(exSb).append("\t").append("comp:").append(compareDetailVO.toString());
        }
        return sb.toString();
    }
}
